package com.gsafety.libraryktx.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.github.mikephil.charting.charts.BarChart
import com.gsafety.libraryktx.R
import com.gsafety.libraryktx.bean.AxisText
import com.gsafety.libraryktx.util.BarChartManager

/**
 * @author : lj
 * @date : 2020/7/30 16:43
 */
class CommonHorizontalBarChart @JvmOverloads constructor(context: Context,
                                                         attrs: AttributeSet? = null,
                                                         defStyleAttr: Int = 0) : LinearLayout(context,attrs,defStyleAttr) {
    var chart: BarChart?=null
    init {
        initview(attrs)
    }
    private fun initview(attrs:AttributeSet?){
        var view = LayoutInflater.from(context).inflate(R.layout.common_horizontal_barchart_layout, this)
        chart=view.findViewById(R.id.chart_bar)
    }
    fun setmoreData(xAxisValues:MutableList<AxisText>, yAxisValues: MutableList<List<Float>>, colors: MutableList<Int>){
        chart?.let {
            var manager= BarChartManager(it)
            manager.showMoreBarChart(context,xAxisValues,yAxisValues,colors)
            manager.setXAxis(xAxisValues.size.toFloat(), 0f, xAxisValues.size+1,false)

        }
    }

    fun setsingleData(xAxisValues: MutableList<AxisText>, yAxisValues: MutableList<Float>, color: MutableList<Int>){
        chart?.let {
            var manager=BarChartManager(it)
            manager.showBarChart(context,xAxisValues,yAxisValues,color)
            manager.setXAxis(xAxisValues.size.toFloat(),-1f, xAxisValues.size+1,false)

        }
    }
}